
package com.yimixian.app.ui;

import com.yimixian.app.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class ShareBoardView extends FrameLayout {
    @InjectView(R.id.wechat_friend_share_view)
    View mWeChatFriendShareView;
    @InjectView(R.id.wechat_circle_share_view)
    View mWeChatCircleShareView;
    @InjectView(R.id.main_frame)
    View mMainFrame;
    @InjectView(R.id.cancel_text)
    View mCancelText;

    public ShareBoardView(Context context) {
        super(context);
        initShareBoardView();
    }

    public ShareBoardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initShareBoardView();
    }

    public ShareBoardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initShareBoardView();
    }

    private void initShareBoardView() {
        LayoutInflater.from(getContext()).inflate(R.layout.socialize_shareboard, this);
        ButterKnife.inject(this);
        OnClickListener cancelClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
            }
        };
        this.setOnClickListener(cancelClickListener);
        mCancelText.setOnClickListener(cancelClickListener);
        Animation animation = AnimationUtils.loadAnimation(getContext(),
                R.anim.socialize_shareboard_animation_in);
        mMainFrame.startAnimation(animation);
    }

    public void setWeChatFriendAndCircleViewClickListener(
            OnClickListener weChatFriendShareViewClickListener,
            OnClickListener weChatCircleShareViewClickListener) {
        mWeChatFriendShareView.setOnClickListener(weChatFriendShareViewClickListener);
        mWeChatCircleShareView.setOnClickListener(weChatCircleShareViewClickListener);
    }

    public void close() {
        Animation animation = AnimationUtils.loadAnimation(getContext(),
                R.anim.socialize_shareboard_animation_out);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (ShareBoardView.this.getParent() != null) {
                    ((ViewGroup) ShareBoardView.this.getParent()).removeView(ShareBoardView.this);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        mMainFrame.startAnimation(animation);
    }

    public void hideWeChatFriendShareView() {
        mWeChatFriendShareView.setVisibility(View.GONE);
        mWeChatCircleShareView.setVisibility(View.VISIBLE);
    }

    public void hideWeChatCircleShareView() {
        mWeChatCircleShareView.setVisibility(View.GONE);
        mWeChatFriendShareView.setVisibility(View.VISIBLE);
    }

    public void showAll() {
        mWeChatCircleShareView.setVisibility(View.VISIBLE);
        mWeChatFriendShareView.setVisibility(View.VISIBLE);
    }
}
